/**
 * Created by ex-yanjun on 14-7-12.
 */
$(function(){
	
	changeNews(1);
	
	$('.selul li').hover(function(){
			$(this).addClass('hovon');
		},function(){
			$(this).removeClass('hovon');
	});
	var zoneId=$("#zoneId").val();
	var cityId=$("#cityId").val();
	var schoolId=$("#schoolId").val();
	var teamId=$("#teamId").val();	
	if(zoneId!=''){
		zoneUl(zoneId);	
		if(cityId!=''){
			cityUl(cityId);
		}
		if(schoolId!=''){
			schoolUl(schoolId);
		}
		if(teamId!=''){
			teamUl(teamId);
		}
		$('.sellight').next().slideToggle('fast');
	}
	$('.sellight').on('click',function(){
		$(this).next().slideToggle('fast');
	});
    

});

function changeNews(i){
	$("span[id^=remarkNewsSpan_]").removeClass().addClass("down");
	$("div[id^=remarkNewsDiv_]").hide();
	$("#remarkNewsLi_1").removeClass().addClass("second");
	$("#remarkNewsLi_2").removeClass().addClass("second");
	$("#remarkNewsLi_3").removeClass().addClass("third");
	if(i==1){
		$("#remarkNewsLi_1").removeClass().addClass("first");
		$("#remarkNewsSpan_"+i).removeClass().addClass("down downshow");
		$("#remarkNewsDiv_"+i).show();
	}else if(i==2){	
		$("#remarkNewsLi_2").removeClass().addClass("first");
		$("#remarkNewsSpan_"+i).removeClass().addClass("down downshow");
		$("#remarkNewsDiv_"+i).show();
	}else{	
		$("#remarkNewsLi_3").removeClass().addClass("first");
		$("#remarkNewsSpan_"+i).removeClass().addClass("down downshow");
		$("#remarkNewsDiv_"+i).show();
	}
	
}

function ajaxGetCity(zoneId){
    if(zoneId!=""){
    	$.ajax({
            url:'/city/queryCityByZoneId.yson?zoneId='+ zoneId,
            type:'POST',
            async:false,
            dataType:"json",
            success:function(date) {
                var liStr = "";
                $(date).each(function(i,obj){                    
                    	liStr += "<li onmousemove='mouseMoveCity("+obj.id+")' onmouseout='mouseOutCity("+obj.id+")' onclick='cityUl("+obj.id+");' id='city_li_"+obj.id+"' value='"+obj.id+"'>"+obj.name+"</li>";                
                });
                $("#city_ul").empty().append(liStr);
                $("#school_ul").empty().append("");
                $("#team_ul").empty().append("");
            }
        });
    }   
}
function ajaxGetSchool(cityId){
    if(cityId!=""){
    	$.ajax({
            url:'/school/querySchoolByCityId.yson?cityId='+ cityId,
            type:'POST',
            async:false,
            dataType:"json",
            success:function(date) {
                var liStr = "";
                $(date).each(function(i,obj){                    
                    	liStr += "<li onmousemove='mouseMoveSchool("+obj.id+")' onmouseout='mouseOutSchool("+obj.id+")' onclick='schoolUl("+obj.id+");' id='school_li_"+obj.id+"' value='"+obj.id+"'>"+obj.name+"</li>";                
                });
                $("#school_ul").empty().append(liStr);
                $("#team_ul").empty().append("");
            }
        });
    }   
}
function ajaxGetTeam(schoolId){
    if(schoolId!=""){
    	$.ajax({
            url:'/playerDate/queryTeamBySchoolId.yson?schoolId='+ schoolId,
            type:'POST',
            async:false,
            dataType:"json",
            success:function(date) {
                var liStr = "";
                $(date).each(function(i,obj){                    
                    	liStr += "<li onmousemove='mouseMoveTeam("+obj.id+")' onmouseout='mouseOutTeam("+obj.id+")' onclick='teamUl("+obj.id+");' id='team_li_"+obj.id+"' value='"+obj.id+"'>"+obj.name+"</li>";                
                });
                $("#team_ul").empty().append(liStr);
            }
        });
    }   
}

function zoneUl(id){
	$("#cityName").text("");
	$("#schoolName").text("");
	$("#teamName").text("");
	$("#zoneId").attr("value",id);
	$("#zone_li_"+id).parent().slideToggle('fast').parent().find('.sellight').text($("#zone_li_"+id).text());
	if(id!=''){//加载城市			
		ajaxGetCity(id);				
	}		
}
function cityUl(id){
	$("#schoolName").text("");
	$("#teamName").text("");
	$("#cityId").attr("value",id);
	$("#city_li_"+id).parent().slideToggle('fast').parent().find('.sellight').text($("#city_li_"+id).text());
	if(id!=''){//加载学校
		ajaxGetSchool(id);
	}
}
function schoolUl(id){
	$("#teamName").text("");
	$("#schoolId").attr("value",id);
	$("#school_li_"+id).parent().slideToggle('fast').parent().find('.sellight').text($("#school_li_"+id).text());
	if(id!=''){//加载球队
		ajaxGetTeam(id);
	}
}
function teamUl(id){
	$("#teamId").attr("value",id);
	$("#team_li_"+id).parent().slideToggle('fast').parent().find('.sellight').text($("#team_li_"+id).text());
}
function searchForm(){
	var zoneId=$("#zoneId").val();
	var cityId=$("#cityId").val();
	var schoolId=$("#schoolId").val();
	var teamId=$("#teamId").val();	
	var teamName=$("#teamName").text();
	if(''==teamName){
		alert("请选择球队");
		return false;
	}	
	if(''==teamId || teamId=='undefined'){
		alert("请选择球队");
		return false;
	}		
	window.location.href='/tnews/newsWebList.html?teamId='+teamId+"&zoneId="+zoneId+"&cityId="+cityId+"&schoolId="+schoolId;
	
	
}
function openDetails(id){
	window.location.href='/tnews/newsWebDetail.html?id='+id;
}

function mouseMoveCity(i){
	$("#city_li_"+i+"").addClass('hovon');
}
	
function mouseOutCity(i){
	$("#city_li_"+i+"").removeClass('hovon');
}

function mouseMoveSchool(i){
	$("#school_li_"+i+"").addClass('hovon');
}

function mouseOutSchool(i){
	$("#school_li_"+i+"").removeClass('hovon');
}

function mouseMoveTeam(i){
	$("#team_li_"+i+"").addClass('hovon');
}

function mouseOutTeam(i){
	$("#team_li_"+i+"").removeClass('hovon');
}
